<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="vue.js"></script>
</head>
<body>
    <div id="app">
        <my-bro1></my-bro1>
        <my-bro2></my-bro2>
    </div>
    <template id="bro1">
        <div>
            兄弟1组件
            <button @click="brodData">广播数据,产生非父子传递的数据</button>
        </div>
    </template>
    <template id="bro2">
        <div>
            兄弟2组件 {{value}}
        </div>
    </template>
    <script>
        const bus = new Vue();
        const bro1 = {
            template: '#bro1',
            methods: {
                brodData(){
                    bus.$emit('my-event', '我是传递到中央总线的消息')
                }
            }
        }
        const bro2 = {
            template: '#bro2',
            data() {
                return {
                    value: ''
                }
            },
            mounted() {
                bus.$on('my-event', val=> {
                    console.log(val);
                    this.value = val;
                })
            }
        }
        new Vue({
            el: '#app',
            components: {
                'myBro1': bro1,
                'myBro2': bro2
            }
        });

    </script>
</body>
</html>